//
//  HomeFloatLayerView.m
//  SHHCPhone
//
//  Created by sheng long on 14-6-27.
//  Copyright (c) 2014年 sheng long. All rights reserved.
//

#import "HomeFloatLayerView.h"
#import "FloatLayerView.h"

#define BORDER_GAP  25

@interface HomeFloatLayerView()
{
    NSArray *contentArray;
    NSArray *numberArray;
    NSString *contentText;
}
@end

@implementation HomeFloatLayerView

@synthesize baseVc;
//@synthesize HomeFloatType;

-(void)setContent:(NSArray*)array tip:(NSString*)text
{
    [baseVc setLeftDrawerViewControllerEnabled:NO];
    
    for (UIView *view in self.subviews) {
        [view removeFromSuperview];
    }
    
    if (array.count == 1) {
        contentArray = @[@{@"text": array.lastObject,@"color": GET_COLOR(@"77dcfd")}];
    }else{
        contentArray = @[@{@"text": @"偏低",@"color": GET_COLOR(@"77dcfd")},@{@"text": @"标准",@"color": GET_COLOR(@"77fd93")},@{@"text": @"偏高",@"color": GET_COLOR(@"ffbb51")}];
    }
    numberArray = array;
    contentText = text;
    
    CGFloat textHeight = 0;
    if (contentText.length>0) {
        textHeight = [z_UI returnHeightFloat:contentText frontSize:FLOATLAYERVIEW_TEXT_FONT frontWidth:250].height+27;
    }    
    
    FloatLayerView *layerView = [[FloatLayerView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width-BORDER_GAP*2, FLOATLAYERVIEW_IMGAE_HEIGHT+textHeight)];
    [layerView setContentArray:contentArray];
    [layerView setNumberArray:numberArray];
    [layerView setContentText:contentText];
    [layerView setBackgroundColor:[UIColor clearColor]];
    [layerView setCenter:CGPointMake(self.frame.size.width/2, self.frame.size.height/2)];
    [self addSubview:layerView];
    
    UIView *bgView = [[UIView alloc] initWithFrame:layerView.frame];
    [bgView setBackgroundColor:GET_COLOR(@"303030")];
    [bgView setAlpha:.8];
    [bgView.layer setCornerRadius:10];
    [self insertSubview:bgView belowSubview:layerView];
    
    [UIView animateWithDuration:.5 animations:^{
        self.alpha = 1;
    } completion:^(BOOL show){
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self action:@selector(bgButt) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
        [button setFrame:self.bounds];
    }];
}

-(void)bgButt
{
    [UIView animateWithDuration:.5 animations:^{
        self.alpha = 0;
    } completion:^(BOOL show){
        for (UIView *view in self.subviews) {
            [view removeFromSuperview];
        }
        [baseVc setLeftDrawerViewControllerEnabled:YES];
    }];
}

@end
